//
//  STComon.h
//  STBasicsApp
//
//  Created by jerry on 2019/5/1.
//  Copyright © 2019 jerry. All rights reserved.
//

#ifndef STComon_h
#define STComon_h

#import "STColor.h"
#import "STFrame.h"
#import "STAPIMacro.h"
#import "STCommonConstant.h"
#import "STThirdKeyConstant.h"
#import "STNoticationConstant.h"



//=================================================常用部分=========================================

#pragma mark -多语言设置
#define ASLocalizedString(key)  [[STLanguageHelper sharedLanguageHelper] languageDisplay:key]

#pragma mark -打印日志
//---------------------打印日志--------------------------
/**
 *  常规日志
 */
#ifdef DEBUG
#define OGLOG(format,...)    \
do{    \
fprintf(stderr, "<%s : %d> %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __func__);    \
(NSLog)((format), ##__VA_ARGS__);    \
fprintf(stderr, "-----------------\n");    \
} while(0);
#else
#define OGLOG(...)
#endif

/**
 *  矩形日志
 */
#ifdef DEBUG
#define OGLOGRect(rect) OGLOG(@"%s x:%.4f, y:%.4f, w:%.4f, h:%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#else
#define OGLOGRect(rect)
#endif

/**
 *  尺寸日志
 */
#ifdef DEBUG
#define OGLOGSize(size) OGLOG(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#else
#define OGLOGSize(size)
#endif

/**
 *  位置日志
 */
#ifdef DEBUG
#define OGLOGPoint(point) OGLOG(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
#else
#define OGLOGPoint(point)
#endif

//---------------------打印日志--------------------------

//获取View的属性
#define OG_GetViewWidth(view)  view.frame.size.width
#define OG_GetViewHeight(view) view.frame.size.height
#define OG_GetViewX(view)      view.frame.origin.x
#define OG_GetViewY(view)      view.frame.origin.y

//MainScreen Height&Width
#define OG_Main_Screen_Height     [[UIScreen mainScreen] bounds].size.height
#define OG_Main_Screen_Width      [[UIScreen mainScreen] bounds].size.width

// MainScreen bounds
#define OG_Main_Screen_Bounds [[UIScreen mainScreen] bounds]

//----------------------系统-----------------------------

#define  OGWEAKSELF      __weak typeof(self) weakself           = self;
#define  OGSTRONGSELF    __strong __typeof(weakself)strongSelf  = weakself;

#define OGKWindow [UIApplication sharedApplication].delegate.window

/**
 *  获取当前屏幕的高度\宽度
 */
#define OG_SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define OG_SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)

/**
 * 设备类型
 */
#define OG_IPHONE_DEVICE (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad)
#define OG_IPAD_DEVICE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

/**
 * 设备UUID
 */
#define OG_IPHONE_DEVICE_UUID ([UIDevice currentDevice].identifierForVendor.UUIDString)

/**
 *  (640, 960)的屏幕
 */
#define OG_iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
/**
 *  (640, 1136)的屏幕
 */
#define OG_iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
/**
 *  (750, 1334)的屏幕
 */
#define OG_iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
/**
 *  (1242, 2208)的屏幕
 */
#define OG_iPhone6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)
/**
 *  (1125,2436)的屏幕
 */
#define OG_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

// 型号
#define OG_IS_IPHONEXR (OG_SCREEN_WIDTH == 414.f && OG_SCREEN_HEIGHT == 896.f ? YES : NO)
#define OG_IS_IPHONEX  (OG_SCREEN_WIDTH == 375.f && OG_SCREEN_HEIGHT == 812.f ? YES : NO)
#define OG_IS_IPHONE_5 ([[UIScreen mainScreen] bounds].size.height == 568.0f)
#define OG_IS_IPHONE_6 ([[UIScreen mainScreen] bounds].size.height == 667.0f)
#define OG_IS_IPHONE_6_PLUS ([[UIScreen mainScreen] bounds].size.height == 736.0f)
#define OG_IS_IPHONE_6_PLUS_UP ([[UIScreen mainScreen] bounds].size.height > 736.0f)

#define OG_StatusBarHeight ((OG_IS_IPHONEX || OG_IS_IPHONEXR) ? 44.f : 20.f)
#define OG_SafeAreaBottomHeight (OG_IS_IPHONEX || OG_IS_IPHONEXR ? 34 : 0)
#define OG_TabbarHeight    (49.f + OG_SafeAreaBottomHeight)
#define OG_NavigationBarHeight (44.f + OG_StatusBarHeight)

/**
 *  判断是否 Retina屏
 */
#define OG_RETINA_SCREEN ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

/**
 *  设备是否ihone 5
 */
#define OG_DEVICE_TYPE_IPHONE_5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

/**
 *  iphone6及以上手机
 */
#define OG_iphone6AndUper ([[UIScreen mainScreen] currentMode].size.width > 640)


//获取当前语言
#define OG_CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

/**
 *  获取系统版本
 */
#define OG_SYSTEM_VERSION_NUMBER [[[UIDevice currentDevice] systemVersion] floatValue]
#define OG_SYSTEM_VERSION [[UIDevice currentDevice] systemVersion]

//App版本号
#define OG_AppMPVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//AppDelegate对象
#define OG_AppDelegateInstance [[UIApplication sharedApplication] delegate]

//判断设备的操做系统是否ios7、ios8、ios9、ios10以上
#define OG_SYSTEM_VERSION_7 (OG_SYSTEM_VERSION_NUMBER >= 7.0)
#define OG_SYSTEM_VERSION_8 (OG_SYSTEM_VERSION_NUMBER >= 8.0)
#define OG_SYSTEM_VERSION_9 (OG_SYSTEM_VERSION_NUMBER >= 9.0)
#define OG_SYSTEM_VERSION_10 (OG_SYSTEM_VERSION_NUMBER >= 10.0)
#define OG_SYSTEM_VERSION_11 (OG_SYSTEM_VERSION_NUMBER >= 11.0)

//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif
#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

/**
 *  对比当前系统版本
 */
#define OG_SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)

#define OG_SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define OG_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define OG_SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define OG_SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)


//----------------------系统-----------------------------


//----------------------内存----------------------------
//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif

#pragma mark - common functions
#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }

//释放一个对象
#define SAFE_DELETE(P) if(P) { [P release], P = nil; }

#define SAFE_RELEASE(x) [x release];x=nil

//----------------------内存----------------------------
#pragma mark -颜色
//----------------------颜色类---------------------------
// rgb颜色转换（16进制->10进制）
#define OG_UIColorWithRGB16Radix(rgbValue) ([UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0])

// 一像素线
#define OG_SINGLE_LINE_WIDTH           (1 / [UIScreen mainScreen].scale)
#define OG_SINGLE_LINE_ADJUST_OFFSET   ((1 / [UIScreen mainScreen].scale) / 2)

// 获取RGB颜色
#define OG_UIColorWithRGBA(r,g,b,a) ([UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a])
#define OG_UIColorWithRGB(r,g,b) (OG_UIColorWithRGBA(r,g,b,1.0f))
#define OG_UIColorWithName(name) ([UIColor name##Color])

//背景色
//#define OG_BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]

//清除背景色
#define OG_UIColorWithNULL ([UIColor clearColor])
//----------------------颜色类--------------------------
#pragma mark -图片
//----------------------图片----------------------------
//读取本地图片
#define OG_UIImageWithPathAndType(path,type) ([UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:path ofType:type]])

//定义UIImage对象
#define OG_UIImageWithPath(path) ([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:path ofType:nil]])

//定义UIImage对象
#define OG_UIImageWithName(name) ([UIImage imageNamed:name])
//建议使用前两种宏定义,性能高于后者

/**
 *  预设图片
 */
#define OG_PLACE_HOLDE_IMG(name)            [UIImage imageNamed:[NSString stringWithFormat:@"placehold_%@",name]]

//----------------------图片----------------------------
#pragma mark -字体
//----------------------字体----------------------------
#define OG_UIFontWithNameAndSize(name,size) ([UIFont fontWithName:name size:size])
#define OG_UIFontWithSize(size) ([UIFont systemFontOfSize:size])
//----------------------字体----------------------------
#pragma mark -路径
//----------------------路径----------------------------
/**
 *  沙盒
 */
//Home(根路径)
#define OG_HOME_DIRECTORY NSHomeDirectory()
//Documents
#define OG_DOCUMENTS_DIRECTORY (NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0])
//Library
#define OG_LIBRARY_DIRECTORY (NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0])
//Cache
#define OG_CACHE_DIRECTORY (NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0])
//tmp
#define OG_TMP_DIRECTORY NSTemporaryDirectory()

//Library/Caches 文件路径
#define OG_FilePath ([[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil])

//数据库名称
#define OG_PROJECT_DB_NAME @"OGbase.db"
//数据库路径
#define OG_FETCH_DB_PATH ([CACHE_DIRECTORY stringByAppendingPathComponent:OG_PROJECT_DB_NAME])

/**
 *  Bundle
 */
#define OG_MAIN_BUNDLE ([NSBundle mainBundle])
//Bundle文件路径
#define OG_FilePathInBundleWithNameAndType(name,type) ([MAIN_BUNDLE pathForResource:name ofType:type])

/**
 *  崩溃日志的文件
 *
 */
#define OG_CRASH_FILE_PATH [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"crash.txt"]
/**
 *  缓存图片的地址
 */
#define OG_IMGCACHE_SAVE_PATH [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"imgCache"]
/**
 *  相册的地址
 */
#define OG_IMG_SAVE_PATH [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"imgAlbum"]

//----------------------路径----------------------------
#pragma mark -快捷转字符串
//----------------------快捷转字符串---------------------
#define OG_StringInt(s) [NSString stringWithFormat:@"%d",(int)s]
#define OG_StringBool(s) [NSString stringWithFormat:@"%d",s]
#define OG_StringString(s) [NSString stringWithFormat:@"%@",s]
//----------------------快捷转字符串---------------------
#pragma mark -线程
//----------------------线程----------------------------

///用宏定义检测block是否可用!
#define BLOCK_EXEC(block, ...) if (block) { block(__VA_ARGS__); };

//G－C－D
#define OG_BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define OG_MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//GCD多线程
#define OG_Common_BackGroundFun(aFun) dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){aFun;} );
#define OG_Common_MainFun(aFun) dispatch_async( dispatch_get_main_queue(), ^(void){aFun;} );

//在Main线程上运行
#define OG_DISPATCH_ON_MAIN_THREAD(mainQueueBlock) dispatch_async(dispatch_get_main_queue(), mainQueueBlock);
//在Global Queue上运行
#define OG_DISPATCH_ON_GLOBAL_QUEUE_HIGH(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), globalQueueBlocl);
#define OG_DISPATCH_ON_GLOBAL_QUEUE_DEFAULT(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl);
#define OG_DISPATCH_ON_GLOBAL_QUEUE_LOW(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), globalQueueBlocl);
#define OG_DISPATCH_ON_GLOBAL_QUEUE_BACKGROUND(globalQueueBlocl) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), globalQueueBlocl);
//----------------------线程----------------------------

#define KOGScaleLength(length) (length) * [UIScreen mainScreen].bounds.size.width / 320.0f




#endif /* STComon_h */
